<?php
/*
# ------------------------------------------------------------------------
# JA Job Board Package
# ------------------------------------------------------------------------
# Copyright (C) 2004-2010 JoomlArt.com. All Rights Reserved.
# @license GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
# Author: JoomlArt.com
# Websites: http://www.joomlart.com - http://www.joomlancers.com.
# ------------------------------------------------------------------------
*/

/**
* This controller is used for JAEmail feature of the component
*/
class JAJobBoardControllerJAPermission extends JAJobBoardController {
/**
     * Constructor
     */
    function __construct( $location = array() )
    {
    	
        parent::__construct( $location );  
        checkPermission_Administrator('permission');    
        // Register Extra tasks
        $this->registerTask( 'apply',   'save' );        
        $this->registerTask( 'apply_group',   'save_group' );        
    }
    
    /**
    * Display current japerminission of the component to administrator
    * 
    */
    function display(){
    	
    	switch($this->getTask())
		{			
			case 'edit':
			{
				JRequest::setVar( 'hidemainmenu', 1 );
				JRequest::setVar( 'edit', true );
				JRequest::setVar( 'layout', 'form' );
			
			} break;
			case 'bygroup':
			{
				JRequest::setVar( 'hidemainmenu', 1 );
				JRequest::setVar( 'edit', true );
				JRequest::setVar( 'layout', 'group' );
			
			} break;
		}
		
		parent::display();
    }
    
    /**
    * Cancel current operation
    * 
    */
    function cancel(){
    	global $option;
    	$usergroup = JRequest::getVar('usergroup', 'admin');
        $this->setRedirect("index.php?option=$option&view=japermission&usergroup=$usergroup");
    }     
	
	/**
	* Save categories record
	*/
	function save(){
		global $option;
		$model = $this->getModel('japermission');
		$post		= JRequest::get( 'post' );
		
		$user_id = JRequest::getVar('cid',  0, '', 'array');
		$user_id = (int)$user_id[0];
		$usergroup = JRequest::getVar('usergroup', 'admin');
		
//		if( isset($post['cb'])){
			$msg = $model->store();
//		}
		
		
		switch ( $this->_task ) {
			case 'apply':
				$this->setRedirect( "index.php?option=$option&view=japermission&task=edit&usergroup=$usergroup&cid[]=$user_id" , $msg );
				break;

			case 'save':
			default:
				$this->setRedirect( "index.php?option=$option&view=japermission&usergroup=$usergroup", $msg );
				break;
		}		
	}	
	
	function save_group(){
		global $option;
		$model = $this->getModel('japermission');
		$post		= JRequest::get( 'post' );
			
		$usergroup = JRequest::getVar('usergroup', 'admin');
		
		JRequest::setVar('usertype', 'Guest');
		
//		if( $post['cb']>0){
			$msg = $model->store_group();
//		}
//		else {
//			$msg = JText::_( 'YOU MUST SELECT PERMISSION' );
//		}
		
		$this->setRedirect( "index.php?option=$option&view=japermission&usergroup=$usergroup" , $msg );
	}	
}